#ifndef _WX_ODCOMBO_H_
#define _WX_ODCOMBO_H_

#include "wx/defs.h"

#if wxUSE_ODCOMBOBOX

#include "wx/combo.h"
#include "wx/ctrlsub.h"
#include "wx/vlbox.h"
#include "wx/timer.h"

enum {
  wxODCB_DCLICK_CYCLES            = wxCC_SPECIAL_DCLICK,
  wxODCB_STD_CONTROL_PAINT        = 0x1000
};

enum {
  wxODCB_PAINTING_CONTROL         = 0x0001,
  wxODCB_PAINTING_SELECTED        = 0x0002
};

class wxVListBoxComboPopup : public wxVListBox,
  public wxComboPopup {
    friend class wxOwnerDrawnComboBox;
  public:
    wxVListBoxComboPopup() : wxVListBox(), wxComboPopup() { }
    virtual ~wxVListBoxComboPopup();
    virtual void Init();
    virtual bool Create( wxWindow* parent );
    virtual wxWindow *GetControl() { return this; }
    virtual void SetStringValue( const wxString& value );
    virtual wxString GetStringValue() const;
    virtual void OnPopup();
    virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight );
    virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
    virtual void OnComboKeyEvent( wxKeyEvent& event );
    virtual void OnComboDoubleClick();
    virtual bool LazyCreate();
    void SetSelection( int item );
    void Insert( const wxString& item, int pos );
    int Append( const wxString& item );
    void Clear();
    void Delete( unsigned int item );
    void SetItemClientData( unsigned int n, void* clientData, wxClientDataType clientDataItemsType );
    void *GetItemClientData( unsigned int n ) const;
    void SetString( int item, const wxString& str );
    wxString GetString( int item ) const;
    unsigned int GetCount() const;
    int FindString( const wxString& s, bool bCase = false ) const;
    int GetSelection() const;
    void Populate( const wxArrayString& choices );
    void ClearClientDatas();
    int GetItemAtPosition( const wxPoint& pos ) { return HitTest( pos ); }
    wxCoord GetTotalHeight() const { return EstimateTotalHeight(); }
    wxCoord GetLineHeight( int line ) const { return OnGetLineHeight( line ); }
  protected:
    bool HandleKey( int keycode, bool saturate, wxChar unicode = 0 );
    void SendComboBoxEvent( int selection );
    void DismissWithEvent();
    void ItemWidthChanged( unsigned int item ) {
      m_widths[item] = -1;
      m_widthsDirty = true;
    }
    virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
    virtual wxCoord OnMeasureItem( size_t item ) const;
    virtual wxCoord OnMeasureItemWidth( size_t item ) const;
    virtual void OnDrawBg( wxDC& dc, const wxRect& rect, int item, int flags ) const;
    virtual void OnDrawItem( wxDC& dc, const wxRect& rect, size_t n ) const;
    void OnDrawBackground( wxDC& dc, const wxRect& rect, size_t n ) const;
    void OnMouseMove( wxMouseEvent& event );
    void OnMouseWheel( wxMouseEvent& event );
    void OnKey( wxKeyEvent& event );
    void OnLeftClick( wxMouseEvent& event );
    int GetWidestItemWidth() { CalcWidths(); return m_widestWidth; }
    int GetWidestItem() { CalcWidths(); return m_widestItem; }
    void StopPartialCompletion();
    wxArrayString           m_strings;
    wxArrayPtrVoid          m_clientDatas;
    wxFont                  m_useFont;
    int                     m_value; // selection
    int                     m_itemHover; // on which item the cursor is
    int                     m_itemHeight; // default item height (calculate from font size
    wxClientDataType        m_clientDataItemsType;
  private:
    wxArrayInt              m_widths;
    int                     m_widestWidth;
    int                     m_widestItem;
    bool                    m_widthsDirty;
    bool                    m_findWidest;
    bool                    m_clicked;
    void CalcWidths();
    wxString                m_partialCompletionString;

    #if wxUSE_TIMER
    wxTimer                 m_partialCompletionTimer;
    #endif // wxUSE_TIMER

    DECLARE_EVENT_TABLE()
};

class wxOwnerDrawnComboBox : public wxComboCtrl,
  public wxItemContainer {
    friend class wxVListBoxComboPopup;
  public:
    wxOwnerDrawnComboBox() : wxComboCtrl() { Init(); }
    wxOwnerDrawnComboBox( wxWindow *parent,
                          wxWindowID id,
                          const wxString& value,
                          const wxPoint& pos,
                          const wxSize& size,
                          int n,
                          const wxString choices[],
                          long style = 0,
                          const wxValidator& validator = wxDefaultValidator,
                          const wxString& name = wxComboBoxNameStr )
      : wxComboCtrl() {
      Init();
      ( void )Create( parent, id, value, pos, size, n,
                      choices, style, validator, name );
    }

    bool Create( wxWindow *parent,
                 wxWindowID id,
                 const wxString& value = wxEmptyString,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxComboBoxNameStr );

    wxOwnerDrawnComboBox( wxWindow *parent,
                          wxWindowID id,
                          const wxString& value,
                          const wxPoint& pos,
                          const wxSize& size,
                          const wxArrayString& choices,
                          long style,
                          const wxValidator& validator = wxDefaultValidator,
                          const wxString& name = wxComboBoxNameStr );

    bool Create( wxWindow *parent,
                 wxWindowID id,
                 const wxString& value,
                 const wxPoint& pos,
                 const wxSize& size,
                 int n,
                 const wxString choices[],
                 long style = 0,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxComboBoxNameStr );

    bool Create( wxWindow *parent,
                 wxWindowID id,
                 const wxString& value,
                 const wxPoint& pos,
                 const wxSize& size,
                 const wxArrayString& choices,
                 long style = 0,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxComboBoxNameStr );

    virtual ~wxOwnerDrawnComboBox();
    void SetPopupControl( wxVListBoxComboPopup* popup ) {
      DoSetPopupControl( popup );
    }
    virtual void Clear();
    virtual void Delete( unsigned int n );
    virtual unsigned int GetCount() const;
    virtual wxString GetString( unsigned int n ) const;
    virtual void SetString( unsigned int n, const wxString& s );
    virtual int FindString( const wxString& s, bool bCase = false ) const;
    virtual void Select( int n );
    virtual int GetSelection() const;
    virtual void SetSelection( int n ) { Select( n ); }
    virtual void SetSelection( long from, long to ) {
      wxComboCtrl::SetSelection( from, to );
    }
    virtual int GetWidestItemWidth() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItemWidth(); }
    virtual int GetWidestItem() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItem(); }
    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
  protected:
    virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
    virtual wxCoord OnMeasureItem( size_t item ) const;
    virtual wxCoord OnMeasureItemWidth( size_t item ) const;
    virtual void OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const;
    virtual void DoSetPopupControl( wxComboPopup* popup );
    void ClearClientDatas();
    wxVListBoxComboPopup* GetVListBoxComboPopup() const {
      return ( wxVListBoxComboPopup* ) m_popupInterface;
    }

    virtual int DoAppend( const wxString& item );
    virtual int DoInsert( const wxString& item, unsigned int pos );
    virtual void DoSetItemClientData( unsigned int n, void* clientData );
    virtual void* DoGetItemClientData( unsigned int n ) const;
    virtual void DoSetItemClientObject( unsigned int n, wxClientData* clientData );
    virtual wxClientData* DoGetItemClientObject( unsigned int n ) const;
    wxArrayString           m_initChs;
  private:
    void Init();
    DECLARE_EVENT_TABLE()
    DECLARE_DYNAMIC_CLASS( wxOwnerDrawnComboBox )
};

#endif
#endif
